home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: nntp.coast.net!torn!utnut!utgpu!normb
- From: normb@gpu.utcc.utoronto.ca (Norman Baccari)
- Subject: Re: Opening Libraries "Quietly"
- Message-ID: <DM2uyG.Muz@gpu.utcc.utoronto.ca>
- Organization: UTCC Public Access
- Distribution: All
- Date: Thu, 1 Feb 1996 03:27:52 GMT
-
- >
- >
- > : Two Questions...
- >
- > : From what I understand, when calling OpenLib() this causes the
- > : library thats being opened to call its own init proceedure.
- > : I want to open the library to get Ver/Rev and id_string and
- > : quietly leave without affecting anything. When I do this now
- > : some libraries do there "init thing" and will try and run
- > : themselves. Toolmanager.library will do this and so does
- > : vmm.library. In an extreme case the system will crash on the
- > : OpenLib() as it does when the amos.library opened. Is there a
- > : way to get the info I want from any disk based library,
- > : quietly & legally?
- >
- > First, LoadSeg() the library. This will give you a BPTR to the library
- > code. Use the BADDR() macro to convert this to an APTR and cast the
- > result to LONG *. Add 2. Then cast the result to struct Resident * and
- > read the values out of the Resident structure. i.e.
- >
- > BPTR libseg;
- > UWORD libver, librev;
- > struct Resident *libres;
- >
- > if( libseg = LoadSeg(libname) ) /* use _full_ pathname */
- > {
- > /* get pointer to embedded Resident structure */
- > libres = (struct Resident *)((LONG *)BADDR(libseg)+2);
- >
- > /* check that it really is a library */
- > if( ((ULONG *)libres)[-1] != 0x70ff4e75 ||
- > libres->rt_MatchWord != RT_MATCHWORD ||
- > libres->rt_MatchPtr != (APTR)libres )
- > /* rt_MatchPtr is wrong - I forget the real name */
- > {
- > /* copy fields */
- > libver = libres->rt_Version;
- > librev = libres->rt_Revision;
- ^^^^^^^^^^^
- not defined in resident struct
- > }
- > else
- > /* not a library */
- >
- > UnLoadSeg(libseg);
- > }
- > else
- > /* handle the error */
- >
- > You could also fetch the version string while you're at it.
- >
- > : I also need to prevent "non libraries" from being opened. The
- > : library being opened is a user passed argument. If the user
- > : passed a file thats not a library then OpenLib() will crash.
- > : Can I interogate the file internally to detect if its actually
- > : a library that can be opened by OpenLib()?
-
- > See the condition I just added to the code example. This will allow only
- > libraries and devices (which are just a special type of library) to be
- > looked at.
-
- > : Thanks in advance....
- > :
- > : =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- > : Norman Baccari normb@gpu.utcc.utoronto.ca Toronto,Ontario Canada
- > : =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-
- > I hope this works.
- >
- > Ben.
-
- > --
- > Ben Hutchings, student. Finger me on worc0223@sable.ox.ac.uk for
- > various info.
- > email: benjamin.hutchings@worc.ox.ac.uk WWW:
- > http://sable.ox.ac.uk/~worc0223/
- > Users of the world unite! You have nothing to lose but your Micro$oft
- > software
-
- Thanks Ben for the code. I've plugged it in and it seems to work for
- getting the version, and IdString. But its seems that using this
- method trades one problem for another. OpenLib() can cause some
- unstable behaviour but I get Version, Revision and id_String.
- To eliminate the unstable behaviour I can use LoadSeg() but I
- dont get the Revision. Am I to believe that there is no way to
- to obtain all of Version,Revision, and id_string info in a stable
- manner??
-
- I seem to also have another problem using LoadSeg(). When I use
- OpenLib() I can check the existance of an id_string by saying
-
-
- if(LibBase->lib_IdString) /* or if strlen(IdString)>0 then... */
- /* I have an id_string */
- else
- /* No Id_String */
-
- When I do this with the rt_IdString in the Resident
- structure and there is no IdString I get an enforcer hit, even
- though the no IdString condition evaluates as true. How can I
- check for the existance of the IdString without getting an enforcer
- hit when there isnt one?
-
- Once again, thanks.
-
- ---------------------------------------------------------------------
- Norman Baccari | "OK team! You start coding.
- normb@gpu.utcc.utoronto.ca | I'll go see what the user specs are."
- Toronto,Ontario,Canada |
- ---------------------------------------------------------------------
-
-
-